package com.zw.pdm.module.overview.service;

import com.zw.pdm.entity.basic.Dept;
import com.zw.pdm.entity.cost.CosSheet;
import com.zw.pdm.module.cost.service.CostService;
import com.zw.pdm.module.designtask.mapper.DesignTaskMapper;
import com.zw.pdm.module.overview.model.*;
import com.zw.pdm.module.system.mapper.IndexMapper;
import com.zw.pdm.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description:
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@SuppressWarnings("all")
public class HomeService {

    @Autowired
    private IndexMapper indexMapper;
    @Autowired
    private DesignTaskMapper designTaskMapper;
    @Autowired
    private CostService costService;

    /**
     * 个人待办数量
     */
    public WaitHandler getWaitHandler() {
        Integer userId = ShiroUtils.getUserId();
        String code = ShiroUtils.getLoginName();
        String account = ShiroUtils.getUser().getAccount();
        WaitHandler waitHandler = new WaitHandler();
        //1、提报计划待审核（包含变更单）（数量）
        waitHandler.setNum1(indexMapper.getNotCheckReportCount(userId));
        //2、制作件清单待审核（包含变更单）（数量）
        waitHandler.setNum2(indexMapper.getNotCheckMakeCount(userId));
        //3、图纸变更单待审核（包含变更单）（数量）
        waitHandler.setNum3(indexMapper.getNotCheckDrawCount(userId));
        //4、外观设计清单审核（包含变更单）（数量）
        waitHandler.setNum4(indexMapper.getOutwardCount(userId));
        //5、提报计划待提交（包含变更单）（数量）
        waitHandler.setNum5(indexMapper.getNotSubmitReportCount(userId));
        //6、制作件清单待提交（包含变更单）（数量）
        waitHandler.setNum6(indexMapper.getNotSubmitMakeCount(userId));
        //7、图纸变更单待提交（包含变更单）（数量）
        waitHandler.setNum7(indexMapper.getNotSubmitDrawtCount(userId));
        //8、待创建存档清单（数量）
        waitHandler.setNum8(0);
        //9、成本信息定额审核（数量）
//        waitHandler.setNum9(indexMapper.getCostQuotaCount(userId));
        //10、待校对工艺卡（数量）
        waitHandler.setNum10(indexMapper.getNotVerifyCardCount(code));
        //11、存档审核数量
        waitHandler.setNum11(indexMapper.getNotCheckFileCount(userId));
        //12、设计工时确认单待提交
        waitHandler.setNum12(indexMapper.getNotCommitCosCount(account, 1));
        //13、设计工时确认单待审核
        waitHandler.setNum13(getNotCheckCosCount(userId, 1));
        //14、下料工时计划单待提交
        waitHandler.setNum14(indexMapper.getNotCommitCosCount(account, 2));
        //15、下料工时计划单待审核
        waitHandler.setNum15(getNotCheckCosCount(userId, 2));
        //16、铆焊工时计划单待提交
        waitHandler.setNum16(indexMapper.getNotCommitCosCount(account, 3));
        //17、铆焊工时计划单待审核
        waitHandler.setNum17(getNotCheckCosCount(userId, 3));
        //18、热处理计划单待提交
        waitHandler.setNum18(indexMapper.getNotCommitCosCount(account, 4));
        //19、热处理计划单待审核
        waitHandler.setNum19(getNotCheckCosCount(userId, 4));
        //20、装配工时计划单待提交
        waitHandler.setNum20(indexMapper.getNotCommitCosCount(account, 5));
        //21、装配工时计划单待审核
        waitHandler.setNum21(getNotCheckCosCount(userId, 5));
        //22、涂装工时计划单待提交
        waitHandler.setNum22(indexMapper.getNotCommitCosCount(account, 6));
        //23、涂装工时计划单待审核
        waitHandler.setNum23(getNotCheckCosCount(userId, 6));
        //24、安装工时计划单待提交
        waitHandler.setNum24(indexMapper.getNotCommitCosCount(account, 7));
        //25、安装工时计划单待审核
        waitHandler.setNum25(getNotCheckCosCount(userId, 7));
        //26、调试工时确认单待提交
        waitHandler.setNum26(indexMapper.getNotCommitCosCount(account, 8));
        //27、调试工时确认单待审核
        waitHandler.setNum27(getNotCheckCosCount(userId, 8));
        //28、机加工时计划单待提交
        waitHandler.setNum28(indexMapper.getNotCommitCosCount(account, 9));
        //29、机加工时计划单待审核
        waitHandler.setNum29(getNotCheckCosCount(userId, 9));
        //30、项目联络单提交审核（数量）
        waitHandler.setNum30(indexMapper.getNotChenkLuodan(userId));
        return waitHandler;
    }

    /**
     * @param costType 1=设计工时确认 2=下料工时计划 3=铆焊工时计划
     *                 4=热处理计划 5=装配工时计划 6=涂装工时计划 7=安装工时计划
     *                 8=调试工时确认 9=机加工时录入
     * @return 返回成本待审核数量
     */
    private Integer getNotCheckCosCount(Integer userId, Integer costType) {
        CosSheet cosSheet = new CosSheet();
        cosSheet.setCostType(costType);
        cosSheet.setPageQuery(3);// 审核页面
        cosSheet.setVerifyId(userId);
        List<CosSheet> list = costService.findCosSheetByQuery(cosSheet);
        return list.size();
    }

    /**
     * 设计任务总览
     */
    public Box1 getBox1(Integer year, Integer month) {
        Box1 box1 = new Box1();
        box1.setBox1Num1(indexMapper.getDesignRecCount(year, month));
        box1.setBox1Num2(indexMapper.getDesignSendCount(year, month));
        box1.setBox1Num3(indexMapper.getDesignCompCount(year, month));
        box1.setBox1Num4(indexMapper.getDesignCreateCount());
        return box1;
    }

    /**
     * 工艺任务总览数量
     */
    public Box2 getBox2(Integer year, Integer month) {
        Box2 box2 = new Box2();
        box2.setBox2Num1(indexMapper.getCraRecCount(year, month));
        box2.setBox2Num2(indexMapper.getCraSendCount(year, month));
        box2.setBox2Num3(indexMapper.getCraCompCount(year, month));
        box2.setBox2Num4(indexMapper.getCraWaitSendCount(year, month));
        return box2;
    }

    /**
     * 外购件提报计划总览
     */
    public Box3 getBox3(Integer year, Integer month) {
        Box3 box3 = new Box3();
        box3.setBox3Num1(indexMapper.getReportSheetCount(year, month, 5, 1, 1, 1));
        box3.setBox3Num2(indexMapper.getReportSheetCount(year, month, 5, 2, 1, 1));
        box3.setBox3Num3(indexMapper.getReportSheetCount(year, month, 1, 1, 1, 1));
        box3.setBox3Num4(indexMapper.getReportSheetCount(year, month, 1, 2, 1, 1));
        return box3;
    }

    /**
     * 制作件清单总览
     */
    public Box4 getBox4(Integer year, Integer month) {
        Box4 box4 = new Box4();
        box4.setBox4Num1(indexMapper.getMakeCount(year, month, 5, 1, 1));
        box4.setBox4Num2(indexMapper.getMakeCount(year, month, 5, 2, 1));
        box4.setBox4Num3(indexMapper.getMakeCount(year, month, 2, 1, 1));
        box4.setBox4Num4(indexMapper.getMakeCount(year, month, 2, 2, 1));
        box4.setBox4Num5(indexMapper.getMakeCount(year, month, 5, 1, 5));
        box4.setBox4Num6(indexMapper.getMakeCount(year, month, 5, 2, 5));
        box4.setBox4Num7(indexMapper.getMakeCount(year, month, 2, 1, 5));
        box4.setBox4Num8(indexMapper.getMakeCount(year, month, 2, 2, 5));
        return box4;
    }

    /**
     * 图纸变更总览
     */
    public Box5 getBox5(Integer year, Integer month) {
        Box5 box5 = new Box5();
        box5.setBox5Num1(indexMapper.getDrawChangeCount(year, month, 5, 1));
        box5.setBox5Num2(indexMapper.getDrawChangeCount(year, month, 2, 1));
        box5.setBox5Num3(indexMapper.getDrawChangeCount(year, month, 5, 5));
        box5.setBox5Num4(indexMapper.getDrawChangeCount(year, month, 2, 5));
        return box5;
    }

    /**
     * 外观设计总览
     */
    public Box6 getBox6(Integer year, Integer month) {
        Box6 box6 = new Box6();
        box6.setBox6Num1(indexMapper.getOutwardDesignCount(year, month, 5, 1));
        box6.setBox6Num2(indexMapper.getOutwardDesignCount(year, month, 5, 2));
        box6.setBox6Num3(indexMapper.getOutwardDesignCount(year, month, 2, 1));
        box6.setBox6Num4(indexMapper.getOutwardDesignCount(year, month, 2, 2));
        return box6;
    }

    /**
     * 工艺任务总览
     */
    public Box7 getBox7(Integer year, Integer month) {
        Box7 box7 = new Box7();
        box7.setBox7Num1(indexMapper.getMakeSheetCount(year, month, 1, 1));
        box7.setBox7Num2(indexMapper.getMakeSheetCount(year, month, 2, 1));
        box7.setBox7Num3(indexMapper.getMakeSheetCount(year, month, 1, 0));
        box7.setBox7Num4(indexMapper.getMakeSheetCount(year, month, 2, 0));
        box7.setBox7Num5(indexMapper.getDrawChangeSheetCount(year, month, 1));
        box7.setBox7Num6(indexMapper.getDrawChangeSheetCount(year, month, 0));
        box7.setBox7Num7(indexMapper.getNotfitySheetCount(year, month, 1));
        box7.setBox7Num8(indexMapper.getNotfitySheetCount(year, month, 0));
        return box7;
    }

    /**
     * 工艺提报计划总览
     */
    public Box8 getBox8(Integer year, Integer month) {
        Box8 box8 = new Box8();
        box8.setBox8Num1(indexMapper.getReportSheetCount(year, month, 5, 1, 4, 1));
        box8.setBox8Num2(indexMapper.getReportSheetCount(year, month, 5, 2, 4, 1));
        box8.setBox8Num3(indexMapper.getReportSheetCount(year, month, 5, 1, 4, 3));
        box8.setBox8Num4(indexMapper.getReportSheetCount(year, month, 5, 2, 4, 3));
        box8.setBox8Num5(indexMapper.getReportSheetCount(year, month, 5, 1, 4, 2));
        box8.setBox8Num6(indexMapper.getReportSheetCount(year, month, 5, 2, 4, 2));
        box8.setBox8Num7(indexMapper.getReportSheetCount(year, month, 1, 1, 4, 1));
        box8.setBox8Num8(indexMapper.getReportSheetCount(year, month, 1, 2, 4, 1));
        box8.setBox8Num9(indexMapper.getReportSheetCount(year, month, 1, 1, 4, 3));
        box8.setBox8Num10(indexMapper.getReportSheetCount(year, month, 1, 2, 4, 3));
        box8.setBox8Num11(indexMapper.getReportSheetCount(year, month, 1, 1, 4, 2));
        box8.setBox8Num12(indexMapper.getReportSheetCount(year, month, 1, 2, 4, 2));
        return box8;
    }

    /**
     * 按PID查部门
     */
    public List<Dept> findDeptByPid(Integer pid) {
        return designTaskMapper.findDeptByPid(pid);
    }

    public Integer findExecCount(Integer deptId) {
        return indexMapper.findExecCount(deptId);
    }

    public Integer findNotStartedCount(Integer deptId) {
        return indexMapper.findNotStartedCount(deptId);
    }

//    public Integer findCraExecCount(Integer id) {
//        return indexMapper.findCraExecCount(id);
//    }

//    public Integer findCraNotStartedCount(Integer id) {
//        return indexMapper.findCraNotStartedCount(id);
//    }

//    public Integer findCraPartExecCount(Integer id) {
//        return indexMapper.findCraPartExecCount(id);
//    }

//    public Integer findCraPartNotStartedCount(Integer id) {
//        return indexMapper.findCraPartNotStartedCount(id);
//    }
}
